﻿#pragma once
#include "Generation/Piecemeal/Vec.h"
#include "System/GameConfiguration.h"


class TreeEdge
{
public:
	/// <summary>
	/// 起点编号
	/// </summary>
	int Begin;

	/// <summary>
	/// 终点编号
	/// </summary>
	int End;

	/// <summary>
	/// 权值
	/// </summary>
	int Weight;

	/// <summary>
	/// 创建一个 Edge 类的新实例
	/// </summary>
	/// <param name="begin">起点编号</param>
	/// <param name="end">终点编号</param>
	/// <param name="weight">权值</param>

	TreeEdge(int begin, int end, int weight = 0)
	{
		Begin = begin;
		End = end;
		Weight = weight;
	}
};

class FEdgeNode
{
public:
	int Index;
	int Weight;

	FEdgeNode* Next;

	FEdgeNode(int index, int weight = 0, FEdgeNode* next = nullptr)
	{
		if (index < 0)
		{
			UE_LOG(LogTD, Error, TEXT("ERROR_EdgeNode Construment"));
		}

		Index = index;
		Weight = weight;
		Next = next;
	}
};


class FVertexNode
{
public:
	int Index;
	FString VertexName;
	bool Visited;

	FEdgeNode* FirstNode;

	FVertexNode(FString vName, FEdgeNode* firstNode = nullptr)
	{
		VertexName = vName;
		Visited = false;
		FirstNode = firstNode;
	}

	//其他数据
	FVec SettedPos; //放置的位置
	TArray<FVec> FlowedPoses;   //流淌过的位置
	
};

class FSpanTreeNode
{
public:
	FSpanTreeNode* ParentNode;
	FVertexNode* SelfContext;
	FVertexNode* ParentContext;

	TArray<FSpanTreeNode*> ChildrenNodes;
	int Depth = -1;
	int Weight;

public:
	/// <summary>
	/// 构造SpanTreeNode实例
	/// </summary>
	/// <param name="selfName">结点本身的名称</param>
	/// <param name="parentName">结点双亲的名称</param>
	/// <param name="weight">边的权值</param>
	FSpanTreeNode(FVertexNode* selfNode, FVertexNode* parentNode, int weight)
	{
		SelfContext = selfNode;
		ParentContext = parentNode;
		Weight = weight;
	}

	void Flip()
	{
		auto flip = SelfContext;
		SelfContext = ParentContext;
		ParentContext = flip;
	}

	bool IsRoot()
	{
		return ParentNode == nullptr;
	}

	int ChildCount()
	{
		return ChildrenNodes.Num(); //孩子数量
	}
};
